package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.BbsDao;
import com.bysj.dao.impl.BbsDaoImpl;
import com.bysj.entity.Bbs;
import com.bysj.service.BbsService;

public class BbsServiceImpl implements BbsService{
	private BbsDao bd=new BbsDaoImpl();
	@Override
	public void addBBS(Bbs b) {

	}

	@Override
	public void delBBS(Bbs b) {
		String sql="delete from bbs where id= ?";
		bd.delBBS(sql, b);
	}

	@Override
	public int AllBBS() {
		String sql="select count(*) from bbs";
		return bd.AllBBS(sql);
	}

	@Override
	public ArrayList<Bbs> queryAllBBS() {
		String sql="select id,uname,mood,content,time from bbs";
		return bd.queryAllBBS(sql);
	}

	@Override
	public ArrayList<Bbs> FenyequeryAllBBS(int page, int rows) {
		String sql="select id,uname,mood,content,time from bbs limit ?,?";
		return bd.FenyequeryAllBBS(sql, page, rows);
	}

	@Override
	public Bbs queryBbs(Bbs bbs) {
		String sql="";
		return null;
	}

	@Override
	public int CountBbsByUname(Bbs bbs) {
		String sql="select count(*) from bbs where uname like'%"+bbs.getUname()+"%'";
		return bd.AllBBS(sql);
	}

	@Override
	public int CountBbsBycontent(Bbs bbs) {
		String sql="select count(*) from bbs where content like'%"+bbs.getContent()+"%'";
		return bd.AllBBS(sql);
	}

	@Override
	public int CountBbsBytime(Bbs bbs) {
		String sql="select count(*) from bbs where time like'%"+bbs.getTime()+"%'";
		return bd.AllBBS(sql);
	}

	@Override
	public int CountBbsById(Bbs bbs) {
		String sql="select count(*) from bbs where id like'%"+bbs.getId()+"%'";
		return bd.AllBBS(sql);
	}

	@Override
	public ArrayList<Bbs> FenyeQueryByUname(int nowPage, int pageRowNum, Bbs bbs) {
		String sql="select id,uname,mood,content,time"
				+ " from bbs where uname like '%"+bbs.getUname()+"%'"
				+ " limit ?,?";
		return bd.FenyequeryAllBBS(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Bbs> FenyeQueryByContent(int nowPage, int pageRowNum,
			Bbs bbs) {
		String sql="select id,uname,mood,content,time"
				+ " from bbs where content like '%"+bbs.getContent()+"%'"
				+ " limit ?,?";
		return bd.FenyequeryAllBBS(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Bbs> FenyeQueryByTime(int nowPage, int pageRowNum, Bbs bbs) {
		String sql="select id,uname,mood,content,time"
				+ " from bbs where time like '%"+bbs.getTime()+"%'"
				+ " limit ?,?";
		return bd.FenyequeryAllBBS(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Bbs> FenyeQueryById(int nowPage, int pageRowNum, Bbs bbs) {
		String sql="select id,uname,mood,content,time"
				+ " from bbs where id like '%"+bbs.getId()+"%'"
				+ " limit ?,?";
		return bd.FenyequeryAllBBS(sql, nowPage, pageRowNum);
	}

}
